/**   
* @Title: RoleUserMapService.java 
* @Package com.csis.system.service 
* @Description: TODO
* @author dailey  
* @date 2012-10-8
* @version V1.0   
*/
package com.csis.system.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.csis.framework.db.BaseDao;
import com.csis.security.domain.RoleUserMap;
import com.csis.system.common.IStaticData;
import com.csis.system.domain.User;

/**
 * @author dailey
 *
 */
@Service
public class RoleUserMapService {

	@Autowired
	BaseDao baseDao;

	@Transactional
	public void remove(RoleUserMap roleUserMap) {
		baseDao.remove(RoleUserMap.class, roleUserMap.getMapId());
	}

	@Transactional
	public void remove(User user) {
		String sql = "DELETE FROM " + IStaticData.TABLE_ROLE_USER_MAP + " WHERE "
				+ IStaticData.COLUMN_ROLE_USER_MAP_USERID + " = ? ";
		baseDao.execute(sql, user.getId());
	}

	@Transactional
	public void save(RoleUserMap roleUserMap) {
		if (roleUserMap.getMapId() == null) {
			baseDao.persist(roleUserMap);
		} else {
			baseDao.merge(roleUserMap);
		}
	}

}
